#%%
import numpy as np 
import cv2 as cv

# cv.IMREAD_UNCHANGED 表示以原格式读取文件，不做任何改变
img = cv.imread("/home/heron/Desktop/linux_notes/python/opencv/pic1.jpg")

print(img.shape)

cv.imshow("img",img)

a=img[0:50,0:50,0]
cv.waitKey()
img[50:100,100:150,0] = a 

cv.waitKey()
cv.imshow("img",img)
cv.waitKey()
cv.destroyAllWindows()

#%%
# 通道操作
import cv2 as cv
import numpy as np

## 通道拆分
### 索引拆分
img = cv.imread("/home/heron/Desktop/linux_notes/python/img/pic001.jpg")

b = img[:,:,0]
g = img[:,:,1]
r = img[:,:,2]

# 这个是三通道
cv.imshow("a",img)

# 变成了单通道
cv.imshow("img",b) 
cv.waitKey()
cv.imshow("img",g)
cv.waitKey()
cv.imshow("img",r)
cv.waitKey()
cv.destroyAllWindows()
#%%
### 函数拆分 跟索引拆分是一样的效果
b, g,r =cv.split(img)

cv.imshow("b",b) 
cv.waitKey()
cv.imshow("g",g)
cv.waitKey()
cv.imshow("r",r)
cv.destroyAllWindows()

## 通道合并
#%%
bgr = cv.merge([b,g,r])
cv.imshow("bgr",bgr)



rgb = cv.merge([r,g,b])
cv.imshow("rgb",rgb)

cv.waitKey()
cv.destroyAllWindows()


#%%
